<?php
	class dynamic_widget extends Widget 
	{
		public function display($args)
		{
			//print_r($args);
			//$CI =& get_instance();
			if($args['widget_type']=="gallery")
			{
				$widgets=$this->general_model->select_val("galleries","*","short_name = '".$args['short_name']."'");	
			}
			else if($args['widget_type']=="slider")
			{
				$widgets=$this->general_model->select_val("sliders","*","short_name = '".$args['short_name']."'");
			}
			else if($args['widget_type']=="banner")
			{
				$widgets=$this->general_model->select_val("banners","*","short_name = '".$args['short_name']."'");
			}
			else
			{
				$widgets=$this->general_model->select_val("widgets","*","short_name = '".$args['short_name']."'");
			}
			//print_r($widgets);
			switch($widgets['widget_type'])
			{
				case "video":
					$data['widgets']=$this->embedded_video->get_video(strip_tags($widgets['widget_content']),array('height'=>$widgets['widget_height']==0 ? 300 : $widgets['widget_height'] ,'width'=>$widgets['widget_width']==0 ? 400 : $widgets['widget_width']));
					break;
				case "custom":
					$data['widgets']=stripslashes($widgets['widget_content']);
					break;
				case "gallery":
					
					$shortdata = '<link href="'.base_url().'assets/front/css/lightbox.css" rel="stylesheet" />';
					$shortdata .= '<script src="'.base_url().'assets/front/js/lightbox-2.6.min.js"></script>';
					$this->template->javascript->add('lightbox');
					$shortdata.='<div class="image-row">';
					$shortdata.=	'<div class="image-set">';
					$allimages = $this->general_model->select("gallery_images","*","gallery_id = '".$widgets['id']."'");
						
					foreach($allimages as $images)
					{
						$shortdata.=		'<a class="example-image-link" href="'.base_url('assets/uploads/images').'/'.$images['filename'].'" data-lightbox="example-set" title="Click on the right side of the image to move forward."><img class="example-image" src="'.base_url('assets/uploads/images').'/'.$images['filename'].'" alt="Plants: image 1 0f 4 thumb" width="150" height="150"/></a>';
					}
					$shortdata.=	'</div>';
					$shortdata.='</div>';
					$data['widgets']=$shortdata;
					break;
				case "slider":
					if($widgets['slider_type']=="nivoslider")
					{
						$sliderhtml='<script src="'.base_url().'assets/front/js/jquery.nivo.slider.js"></script>';
						//$sliderhtml .= '<link href="'.base_url().'assets/front/css/nivo-slider.css" rel="stylesheet" />';
						$sliderhtml.="<script>$(window).load(function() {
							$('#slider').nivoSlider(
								{
									effect:'fade', //Specify sets like: 'sliceDown,sliceDownLeft,sliceUp,sliceUpLeft,sliceUpDown,sliceUpDownLeft,fold,fade,random'
									slices:15,
									animSpeed:500,
									pauseTime:6000,
									startSlide:0, //Set starting Slide (0 index)
									directionNav:false, //Next & Prev
									directionNavHide:false, //Only show on hover
									controlNav:true, //1,2,3...
									controlNavThumbs:false, //Use thumbnails for Control Nav
									controlNavThumbsFromRel:false, //Use image rel for thumbs
									keyboardNav:true, //Use left & right arrows
									pauseOnHover:false, //Stop animation while hovering
									manualAdvance:false, //Force manual transitions
									captionOpacity:1, //Universal caption opacity
									beforeChange: function(){},
									afterChange: function(){},
									slideshowEnd: function(){} //Triggers after all slides have been shown
								}
							);
						});</script>";
						$sliderhtml.='<div id="slider" class="nivoSlider">';
						$allimages = $this->general_model->select("slider_images","*","slider_id = '".$widgets['id']."' order by sort ASC ");
						$i=1;
						foreach($allimages as $images)
						{
							$sliderhtml.='<img src="'.base_url('assets/uploads/images').'/'.$images['filename'].'" title="#caption'.$i.'" />';
							$i++;
						}
						$sliderhtml.='</div>';
						$sliderhtml.='<div id="caption1" class="nivo-html-caption"><p>Hosting solutions from<span>SpeedHost</span></p></div>';
						$sliderhtml.='<div id="caption2" class="nivo-html-caption"><p>fdgfdgf solutions from<span>SpeedHost</span></p></div>';
    
						$data['widgets']=$sliderhtml;
					}
					else
					{
						$allimages = $this->general_model->select("slider_images","*","slider_id = '".$widgets['id']."' order by sort ASC ");
						$bannerhtml='';
						foreach($allimages as $images)
						{
							$bannerhtml.='<img src="'.base_url('assets/uploads/images').'/'.$images['filename'].'" />';
						}
						
						$data['widgets']=$bannerhtml;
					}
					break;
				case "banner":
					$allimages = $this->general_model->select("banner_images","*","banner_id = '".$widgets['id']."'");
					$bannerhtml='';	
					foreach($allimages as $images)
					{
						$bannerhtml.='<img src="'.base_url('assets/uploads/images').'/'.$images['filename'].'" />';	
					}
					
					$data['widgets']=$bannerhtml;
					break;
				default:
					$data['widgets']="";
			}
			
			$this->load->view('widgets/customwidget', $data);	
		}
	}
?>